﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ProjectVLIB.DA;

namespace ProjectVLIB
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            try
            {
            //    string connectString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=d:\Inet\inet13\TinhNQ\LAB\ProjectVLIB\ESHOPPER.mdf;Integrated Security=True;User Instance=True";
            //    SqlConnection conn = new SqlConnection(connectString);
            //    conn.Open();
            //    label1.Text = "Kết nối thành công";
            //    string sql = "select * from tbl_LoaiHang";
            //    SqlCommand cmd = new SqlCommand(sql, conn);
            //    SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataAccess da = new DataAccess();
                dataGridView1.DataSource = da.GetDataLoaiHang();
                label1.Text = da.GetCountLoaiHang().ToString();

                //conn.Close();
            }
            catch
            {
                label1.Text = "Kết nối thất bại";
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            DataAccess da = new DataAccess();
            string ma = txtSearch.Text;
            dataGridView1.DataSource = da.GetDataLoaiHang(ma);
        }

        private void btmAdd_Click(object sender, EventArgs e)
        {
            DataAccess da = new DataAccess();
            string tenLoaiHang = txtAdd.Text; 
            da.InsertLoaiHang(tenLoaiHang);

            // load lai du lieu
            dataGridView1.DataSource = da.GetDataLoaiHang();
            label1.Text = da.GetCountLoaiHang().ToString();
           
        }


    }
}
